<script setup lang="ts">
import { useUserStore } from '/@/store'

const props = defineProps({
  message: {
    type: Object,
    required: true,
  },
})

const userStore = useUserStore()
</script>

<template>
  <div class="message-avatar-content-container">
    <div v-if="message.fromUid !== userStore.uid" class="box-left">
      <el-popover placement="right" :width="300" trigger="hover">
        <template #reference>
          <div class="avator-outer">
            <el-avatar
              shape="square"
              class="avator"
              :size="50"
              :src="message.avatar"
            ></el-avatar>
          </div>
        </template>
        <div class="externInformation">
          <div class="extern_top">
            <div class="extern_avator_outer">
              <el-image class="extern_avator" :src="message.avatar"></el-image>
            </div>
            <div class="extern_left">
              <div class="user-name">{{ message.username }}</div>
              <div class="user-id">ID: {{ message.fromUid }}</div>
              <div class="user-status">
                <el-tag size="small" type="success">在线</el-tag>
              </div>
            </div>
          </div>
          <div class="extern_middle">
            <div class="info-item">
              <span class="label">性别</span>
              <span class="value">未设置</span>
            </div>
            <div class="info-item">
              <span class="label">地区</span>
              <span class="value">未设置</span>
            </div>
          </div>
          <div class="extern_bottom">
            <div class="bottom_item">
              <el-button type="primary" size="small" class="action-btn">
                <i class="fa fa-user-plus btn-icon"></i>
                <span>添加好友</span>
              </el-button>
            </div>
            <div class="bottom_item">
              <el-button type="success" size="small" class="action-btn">
                <i class="fa fa-comment btn-icon"></i>
                <span>发送消息</span>
              </el-button>
            </div>
          </div>
        </div>
      </el-popover>
      <div class="center">
        <div class="name">
          {{ message.username }}
        </div>
        <div class="text-message-container">
          <p>{{ message.content }}</p>
          <i></i>
        </div>
      </div>
    </div>
    <div v-else class="box-right">
      <div class="avator-outer">
        <el-avatar
          class="avator"
          shape="square"
          :size="50"
          :src="message.avatar"
        ></el-avatar>
      </div>
      <div class="center">
        <div class="name">
          {{ message.username }}
        </div>
        <div class="text-message-container">
          <p>{{ message.content }}</p>
          <i></i>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
$primary-color: #409eff;
$bg-color: #f5f7fa;
$border-color: #e4e7ed;
$text-color: #303133;
$secondary-text: #909399;

.message-avatar-content-container {
  margin-bottom: 20px;

  .box-left,
  .box-right {
    width: 100%;
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;

    .avator {
      height: 50px;
      width: 50px;
      border-radius: 8px;
      box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
    }

    .avator-outer {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .center {
      margin: 0 12px;
      max-width: 70%;

      .name {
        font-size: 13px;
        color: $secondary-text;
        margin-bottom: 4px;
      }

      .text-message-container {
        position: relative;
        padding: 12px 16px;
        border-radius: 12px;
        background-color: #fff;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
        display: inline-block;

        i {
          position: absolute;
          left: -8px;
          top: 12px;
          border: solid transparent;
          border-right-color: #fff;
          border-width: 8px;
        }

        p {
          color: $text-color;
          font-size: 14px;
          line-height: 1.5;
          margin: 0;
          word-break: break-word;
          white-space: pre-line;
        }
      }
    }
  }

  .box-right {
    flex-direction: row-reverse;

    .center {
      .name {
        text-align: right;
      }

      .text-message-container {
        background-color: $primary-color;

        i {
          left: auto;
          right: -8px;
          border-right-color: transparent;
          border-left-color: $primary-color;
        }

        p {
          color: #fff;
        }
      }
    }
  }
}

.externInformation {
  display: flex;
  flex-direction: column;
  min-height: 200px;
  width: 100%;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);

  .extern_top {
    display: flex;
    padding-bottom: 16px;
    border-bottom: 1px solid $border-color;

    .extern_avator_outer {
      flex-shrink: 0;
      margin-right: 16px;

      .extern_avator {
        width: 64px;
        height: 64px;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        object-fit: cover;
      }
    }

    .extern_left {
      flex-grow: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: 8px;

      .user-name {
        font-size: 18px;
        font-weight: 600;
        color: $text-color;
      }

      .user-id {
        font-size: 13px;
        color: $secondary-text;
      }

      .user-status {
        margin-top: 4px;
      }
    }
  }

  .extern_middle {
    padding: 16px 0;
    border-bottom: 1px solid $border-color;

    .info-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;

      &:last-child {
        margin-bottom: 0;
      }

      .label {
        color: $secondary-text;
        font-size: 13px;
      }

      .value {
        color: $text-color;
        font-size: 13px;
      }
    }
  }

  .extern_bottom {
    padding-top: 16px;
    display: flex;
    justify-content: space-between;
    gap: 12px;

    .bottom_item {
      flex: 1;

      .action-btn {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;

        .btn-icon {
          font-size: 14px;
          opacity: 0.9;
          color: currentColor;
        }
      }
    }
  }
}
</style>
